package cn.wolfcode.wolf2w.controller;


import cn.wolfcode.wolf2w.domain.*;
import cn.wolfcode.wolf2w.queryObject.StrategyQueryObject;
import cn.wolfcode.wolf2w.service.*;
import cn.wolfcode.wolf2w.util.JsonResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RequestMapping("destinations")
@RestController
public class DestinationController {
    @Autowired
    private IRegionService regionService;
    @Autowired
    private IDestinationService destinationService;
    @Autowired
    private IStrategyCatalogService strategyCatalogService;
    @Autowired
    private IStrategyService strategyService;
    @Autowired
    private ITravelService travelService;

    @RequestMapping("/hotRegion")
    @ResponseBody
    public Object hotRegion(){

        List<Region> hotRegion = regionService.hotRegion();

        return JsonResult.success(hotRegion);
    }

    @RequestMapping("/search")
    @ResponseBody
    public Object search(String regionId){

        List<Destination> list = destinationService.queryDestByRegionIdForApi(regionId);

        return JsonResult.success(list);
    }

    @RequestMapping("/toasts")
    @ResponseBody
    public Object toasts(StrategyQueryObject qo){

        List<Destination> toasts = destinationService.getToasts(destinationService.get(qo.getDestId()).getParentId());

        return JsonResult.success(toasts);
    }

    @RequestMapping("/detail")
    @ResponseBody
    public Object detail(String id){

        Destination destination = destinationService.get(id);

        return JsonResult.success(destination);
    }

    @RequestMapping("/catalogs")
    @ResponseBody
    public Object catalogs(String destId){

        List<StrategyCatalog> catalogs = strategyCatalogService.queryCatalogsByDestId(destId);

        return JsonResult.success(catalogs);
    }

    @GetMapping("/strategies/viewnumTop3")
    @ResponseBody
    public Object viewnumTop3(String destId){

        List<Strategy> strategies = strategyService.queryViewnumTop3ByDestId(destId);

        return JsonResult.success(strategies);
    }

    @GetMapping("/list")
    @ResponseBody
    public Object list(){
        return JsonResult.success(destinationService.list());
    }


    @GetMapping("/travels/viewnumTop3")
    @ResponseBody
    public Object travelsViewnumTop3(String destId){

        List<Travel> travels = travelService.queryViewnumTop3ByDestId(destId);

        return JsonResult.success(travels);
    }
}
